<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import axios from 'axios'

//导入操作
function imexcel(){
  
    axios.get("http://localhost:8080/imexcel").then((res) => {
    if (res.status == 200) {
      let list = res.data;
      if (list.code == 200) {
        ElMessage({
          message: '导入成功',
          type: 'success',
        })
        // router.push(
        //   {
        //     path:"/show"
        //   }
        // )
      }else{
        ElMessage({
          message: '导入失败',
          type: 'Error',
        })
      }
    }
  })
}

//导出操作
function exexcel(){
//     axios.get("http://localhost:8080/export").then((res) => {
//     if (res.status == 200) {
//       let list = res.data;
//       if (list.code == 200) {
//         ElMessage({
//           message: '导出成功',
//           type: 'success',
//         })
//       }else{
//         ElMessage({
//           message: '导出失败',
//           type: 'Error',
//         })
//       }
//     }
//   })
window.open("http://localhost:8080/export")
}

import { ref } from 'vue'
import type { UploadInstance } from 'element-plus'

const uploadRef = ref<UploadInstance>()

const submitUpload = () => {
  uploadRef.value!.submit()


}

</script>

<template>
    <div class="border">
        <el-upload
    ref="uploadRef"
    class="upload-demo"
    name="uploadFile"
    method="post"
    action="http://localhost:8080/imexcel"
    :auto-upload="false"
  >
    <template #trigger>
      <el-button type="primary">选择文件</el-button>
    </template>

    <el-button class="ml-3" type="success" @click="submitUpload">
      上传
    </el-button>

    <template #tip>
      <div class="el-upload__tip">
        jpg/png 文件类型的文件不能少于500kb
      </div>
    </template>
  </el-upload>
<el-button type="primary" @click="imexcel">导入数据</el-button>
<el-button type="primary" @click="exexcel">导出数据</el-button>

</div>
</template>

<style scoped>
.border {
    margin-left: 250px;
    width: 600px;
}
</style>
